#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

const int MAXN = 2e5+10;
const int MOD = 1e9 + 7;

int h, w, n, r[MAXN], c[MAXN], a[MAXN];

// key=权值，val=点序号
map<int, vector<int>> mp;

int dp[MAXN], rmax[MAXN], cmax[MAXN];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> h >> w >> n;
    for (int i = 1; i <= n; i++) {
        cin >> r[i] >> c[i] >> a[i];
        mp[-a[i]].push_back(i);
    }

    for (auto [_, i] : mp) {
        for (auto j : i)
            dp[j] = max(rmax[r[j]], cmax[c[j]]);
        for (auto j : i) {
            rmax[r[j]] = max(rmax[r[j]], dp[j] + 1);
            cmax[c[j]] = max(cmax[c[j]], dp[j] + 1);
        }
    }

    for (int i = 1; i <= n; i++)cout << dp[i] << endl;
    return 0;
}